package com.jhxx.controller;

import com.jhxx.entity.Integral;
import com.jhxx.service.IntegralService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * Author chengxu
 * Date  2019-12-09
 */
@RestController
@RequestMapping(value = "/integral")
public class IntegralController {
    @Autowired
    private IntegralService integralService;

    @RequestMapping(value = {"/list", ""}, method = RequestMethod.GET)
    public Object list() {
        List<Integral> integrals = integralService.findAllList();
        return integrals;
    }

    @RequestMapping(value = {"/get"}, method = RequestMethod.GET)
    public Object get(@RequestParam String id) {
        Integral integral = integralService.get(id);
        return integral;
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public String insert(@RequestBody Integral integral) {
        if (integralService.insert(integral) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    @RequestMapping(value = "/insertBatch", method = RequestMethod.POST)
    public String insertBatch(@RequestBody List<Integral> integrals) {
        if (integralService.insertBatch(integrals) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(@RequestBody Integral integral) {
        if (integralService.update(integral) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public String delete(@RequestBody Integral integral) {
        if (integralService.delete(integral) > 0) {
            return "success";
        } else {
            return "failed";
        }
    }

}
